//
//  InviteViewController.m
//  XRSquare
//
//  Created by UaenaMo on 2018/8/14.
//  Copyright © 2018年 UaenaMo. All rights reserved.
//

#import "InviteViewController.h"
#import <UMShare/UMShare.h>
@interface InviteViewController ()
{
    
}
@end

@implementation InviteViewController


-(void)backAction
{
    [self.navigationController popViewControllerAnimated:YES];
    self.navigationController.navigationBarHidden = YES;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationController.navigationBarHidden = NO;
    self.navigationController.navigationBar.tintColor = [UIColor grayColor];
    self.navigationItem.title = @"邀请好友";
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"back"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate] style:UIBarButtonItemStylePlain target:self action:@selector(backAction)];
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    CGRect rectStatus = [[UIApplication sharedApplication] statusBarFrame];
    CGRect rectNav = self.navigationController.navigationBar.frame;
    
    UILabel * title = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 30)];
    title.font = [UIFont systemFontOfSize:20];
    [self.view addSubview:title];
    
    UIButton * wechatbutton = [[UIButton alloc]initWithFrame:CGRectMake(0, rectNav.size.height + rectStatus.size.height, ScreenWidth, (ScreenHeight - rectNav.size.height - rectStatus.size.height)/3)];
    [wechatbutton addTarget:self action:@selector(wechatAction) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:wechatbutton];
    
    {
        UIImageView * wechat = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 50, 50)];
        wechat.image = [UIImage imageNamed:@"微信"];
        wechat.center = CGPointMake(ScreenWidth/2, wechatbutton.frame.size.height/2);

        [wechatbutton addSubview:wechat];
        
        UILabel * wechatTitle = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 20)];
        wechatTitle.font = [UIFont systemFontOfSize:15];
        wechatTitle.textAlignment = NSTextAlignmentCenter;
        wechatTitle.text = @"微信好友";
        wechatTitle.center = CGPointMake(ScreenWidth/2, wechatbutton.frame.size.height/2 + 40);
        [wechatbutton addSubview:wechatTitle];
        
        UIView * line = [[UIView alloc]initWithFrame:CGRectMake(0, wechatbutton.frame.origin.y + wechatbutton.frame.size.height, ScreenWidth, 1)];
        line.backgroundColor = [UIColor colorFromHexCode:@"f3f3f3"];
        [self.view addSubview:line];
    }
    
    UIButton * wechatFriend = [[UIButton alloc]initWithFrame:CGRectMake(0, rectNav.size.height + rectStatus.size.height + (ScreenHeight - rectNav.size.height - rectStatus.size.height)/3, ScreenWidth, (ScreenHeight - rectNav.size.height - rectStatus.size.height)/3)];
    [wechatFriend addTarget:self action:@selector(wechatFriendAction) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:wechatFriend];
    
    {
        UIImageView * wechat = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 50, 50)];
        wechat.image = [UIImage imageNamed:@"朋友圈"];
        wechat.center = CGPointMake(ScreenWidth/2, wechatbutton.frame.size.height/2);

        [wechatFriend addSubview:wechat];
        
        UILabel * wechatTitle = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 20)];
        wechatTitle.font = [UIFont systemFontOfSize:15];
        wechatTitle.textAlignment = NSTextAlignmentCenter;
        wechatTitle.text = @"微信朋友圈";
        wechatTitle.center = CGPointMake(ScreenWidth/2, wechatbutton.frame.size.height/2 + 40);
        [wechatFriend addSubview:wechatTitle];
        
        UIView * line = [[UIView alloc]initWithFrame:CGRectMake(0, wechatFriend.frame.origin.y + wechatFriend.frame.size.height, ScreenWidth, 1)];
        line.backgroundColor = [UIColor colorFromHexCode:@"f3f3f3"];
        [self.view addSubview:line];
    }
    
    UIButton * qq = [[UIButton alloc]initWithFrame:CGRectMake(0, rectNav.size.height + rectStatus.size.height + (ScreenHeight - rectNav.size.height - rectStatus.size.height)/3 + (ScreenHeight - rectNav.size.height - rectStatus.size.height)/3, ScreenWidth, (ScreenHeight - rectNav.size.height - rectStatus.size.height)/3)];
    [qq addTarget:self action:@selector(qqAction) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:qq];
    
    {
        UIImageView * wechat = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 50, 50)];
        wechat.image = [UIImage imageNamed:@"qq"];
        wechat.center = CGPointMake(ScreenWidth/2, wechatbutton.frame.size.height/2);

        [qq addSubview:wechat];
        
        UILabel * wechatTitle = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 20)];
        wechatTitle.font = [UIFont systemFontOfSize:15];
        wechatTitle.textAlignment = NSTextAlignmentCenter;
        wechatTitle.text = @"qq好友";
        wechatTitle.center = CGPointMake(ScreenWidth/2, wechatbutton.frame.size.height/2 + 40);
        [qq addSubview:wechatTitle];
        
        UIView * line = [[UIView alloc]initWithFrame:CGRectMake(0, qq.frame.origin.y + qq.frame.size.height, ScreenWidth, 1)];
        line.backgroundColor = [UIColor colorFromHexCode:@"f3f3f3"];
        [self.view addSubview:line];
    }
}

-(void)wechatAction
{
    //创建分享消息对象
    UMSocialMessageObject *messageObject = [UMSocialMessageObject messageObject];
    //创建网页内容对象
    UMShareWebpageObject *shareObject = [UMShareWebpageObject shareObjectWithTitle:@"蓄锐广场" descr:@"蓄锐广场——我的成长伴侣" thumImage:[UIImage imageNamed:@"logoS"]];
    //设置网页地址
    shareObject.webpageUrl = @"https://app.xrsquare.com/apiv1/DownloadApp?from=singlemessage";
    //分享消息对象设置分享内容对象
    messageObject.shareObject = shareObject;
    //调用分享接口
    [[UMSocialManager defaultManager] shareToPlatform:UMSocialPlatformType_WechatSession messageObject:messageObject currentViewController:self completion:^(id data, NSError *error) {
        if (error) {
            UMSocialLogInfo(@"************Share fail with error %@*********",error);
        }else{
            if ([data isKindOfClass:[UMSocialShareResponse class]]) {
                UMSocialShareResponse *resp = data;
                //分享结果消息
                UMSocialLogInfo(@"response message is %@",resp.message);
                //第三方原始返回的数据
                UMSocialLogInfo(@"response originalResponse data is %@",resp.originalResponse);
            }else{
                UMSocialLogInfo(@"response data is %@",data);
            }
        }
    }];
     
}

-(void)wechatFriendAction
{
  
    //创建分享消息对象
    UMSocialMessageObject *messageObject = [UMSocialMessageObject messageObject];
    //创建网页内容对象
    UMShareWebpageObject *shareObject = [UMShareWebpageObject shareObjectWithTitle:@"蓄锐广场" descr:@"蓄锐广场——我的成长伴侣" thumImage:[UIImage imageNamed:@"logoS"]];
    //设置网页地址
    shareObject.webpageUrl = @"https://app.xrsquare.com/apiv1/DownloadApp?from=singlemessage";
    //分享消息对象设置分享内容对象
    messageObject.shareObject = shareObject;
    //调用分享接口
    [[UMSocialManager defaultManager] shareToPlatform:UMSocialPlatformType_WechatTimeLine messageObject:messageObject currentViewController:self completion:^(id data, NSError *error) {
        if (error) {
            UMSocialLogInfo(@"************Share fail with error %@*********",error);
        }else{
            if ([data isKindOfClass:[UMSocialShareResponse class]]) {
                UMSocialShareResponse *resp = data;
                //分享结果消息
                UMSocialLogInfo(@"response message is %@",resp.message);
                //第三方原始返回的数据
                UMSocialLogInfo(@"response originalResponse data is %@",resp.originalResponse);
            }else{
                UMSocialLogInfo(@"response data is %@",data);
            }
        }
    }];
}

-(void)qqAction
{
   
    //创建分享消息对象
    UMSocialMessageObject *messageObject = [UMSocialMessageObject messageObject];
    //创建网页内容对象
    UMShareWebpageObject *shareObject = [UMShareWebpageObject shareObjectWithTitle:@"蓄锐广场" descr:@"蓄锐广场——我的成长伴侣" thumImage:[UIImage imageNamed:@"logoS"]];
    //设置网页地址
    shareObject.webpageUrl = @"https://app.xrsquare.com/apiv1/DownloadApp?from=singlemessage";
    //分享消息对象设置分享内容对象
    messageObject.shareObject = shareObject;
    //调用分享接口
    [[UMSocialManager defaultManager] shareToPlatform:UMSocialPlatformType_QQ messageObject:messageObject currentViewController:self completion:^(id data, NSError *error) {
        if (error) {
            UMSocialLogInfo(@"************Share fail with error %@*********",error);
        }else{
            if ([data isKindOfClass:[UMSocialShareResponse class]]) {
                UMSocialShareResponse *resp = data;
                //分享结果消息
                UMSocialLogInfo(@"response message is %@",resp.message);
                //第三方原始返回的数据
                UMSocialLogInfo(@"response originalResponse data is %@",resp.originalResponse);
            }else{
                UMSocialLogInfo(@"response data is %@",data);
            }
        }
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
